home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Palettes / MiscGaugePalette / MiscGaugeView.subproj / Gauge.psw next >
Encoding:
Text File  |  1995-04-14  |  2.5 KB  |  112 lines

  1. /*
  2.  * Gauge.psw, Postscript code for drawing analog gauge.
  3.  * Author: Bruce Blumberg, NeXT Developer Support Group.
  4.  * Originally written for 0.6 mid 1988, modified for 1.0 by Ali Ozer.
  5.  * Cleaned and spiffed up for 2.0 by Julie Zelenski.
  6.  * Took away the /mhand function since it didn't work for multiple
  7.  * instances of the gauge (if they were different sizes). Also took most
  8.  * of the setgray calls out so I could use color. Just the borders still
  9.  * use grays (and it checks to make sure it is not the same gray as the
  10.  * face is drawn in). February 26, 1995 by Todd Thomas.
  11.  * You may freely copy, distribute and reuse the code in this example.  
  12.  * NeXT disclaims any warranty of any kind, expressed or implied, as to 
  13.  * its fitness for any particular use.
  14.  * Thank you NeXT, I will take you up on that.
  15.  */
  16.  
  17.  
  18. /* PSWdrawBorder draws the border and background of the gauge face.
  19.  */
  20. defineps PSWdrawBorder(float x; float y; float radius)
  21.     x y radius 1.5 add 0 360 arc
  22.     fill 
  23.     1.0 setlinewidth
  24.     % if the current gray is white, then use light gray.
  25.     currentgray 1.0 eq {0.333} {1.0} ifelse
  26.     setgray
  27.     x y radius 2 add 50 220 arc
  28.     stroke
  29.     1.5 setlinewidth
  30.     % if the current gray is dark gray, use light.
  31.     currentgray 0.333 eq {0.667} {0.333} ifelse
  32.     setgray
  33.     x y radius 2 add 220 50 arc
  34.     stroke
  35.     1.0 setlinewidth
  36.     % if the current gray is black, use dark gray.
  37.     currentgray 0.0 eq {0.333} {0.0} ifelse
  38.     setgray
  39.     x y radius 1.5 add 220 50 arc
  40.     stroke
  41. endps
  42.  
  43.  
  44. /* PSWdrawTicks draws a tick mark at each increment around the circle 
  45.  * from the start to the stop angle.
  46.  */
  47. defineps PSWdrawTicks(float x; float y; float radius; float increment; float start; float stop)
  48.     .5 setlinewidth
  49.     gsave
  50.     x y translate
  51.     start rotate
  52.     start increment stop {
  53.         newpath
  54.         radius 0 moveto
  55.         -3 0 rlineto
  56.         closepath
  57.         stroke
  58.         increment neg rotate
  59.     } for
  60.     grestore
  61. endps
  62.  
  63.  
  64. /* PSWdrawString simply draws string at specific location 
  65.  */
  66. defineps PSWdrawString(float x; float y; char *str)
  67.     x y moveto
  68.     (str) show
  69. endps
  70.  
  71.  
  72. /* PSWdrawHand translate and rotates the coordinate system, then 
  73.  * draws the gauge hand.
  74.  */
  75.               
  76. defineps PSWdrawHand(float x; float y; float ang; float length)
  77.     gsave
  78.     x y translate
  79.     ang rotate
  80.  
  81.     0 setlinewidth
  82.     newpath
  83.         0 3.5 moveto
  84.         0 0 3.5 90 270 arc
  85.         length 3.5 rlineto
  86.         length neg 3.5 rlineto
  87.     closepath 
  88.     fill
  89.     newpath
  90.         0 2 moveto
  91.         0 0 1.5 0 360 arc
  92.         closepath
  93.         1.0 currentgray sub setgray
  94.     closepath
  95.     fill
  96.  
  97.     grestore
  98. endps
  99.  
  100.  
  101. /* For if we are drawing in a flipped view (a matrix perhaps). */
  102.  
  103. defineps PSWflipme (float height)
  104.  
  105. 1.0 -1.0 scale
  106. 0.0 height neg translate
  107.  
  108. endps
  109.  
  110.  
  111.  
  112.